﻿using System;
using CollegeSim.Domain.Entities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CollegeSim.Domain.Test.Entities
{
    // Author: Ryan Redburn
    // Project: CollegeSim
    // Date: 5/18/2014

    [TestClass]
    public class SessionTest
    {
        #region [ SessionID ]

        [TestMethod]
        public void SessionID_DefaultValue_EqualsExpected()
        {
            // Arrange
            var session = new Session();

            // Assert
            Assert.AreEqual(0, session.SessionID);
        }

        #endregion

        #region [ CRN ]

        [TestMethod]
        public void SessionCRN_Empty_ArgumentNullException()
        {
            // Arrange
            var assert = false;
            var session = new Session
            {
                CRN = "1904",
                Capacity = 30,
                Course = new Course
                {
                    CourseID = 1,
                    Subject = "CIT",
                    Number = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    Online = false,
                    Hybrid = false
                },
                Instructor = new Instructor
                {
                    InstructorID = 1,
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    OfficeNumber = "IS201"
                },
                Semester = new Semester
                {
                    SemesterID = 1,
                    Name = "Spring"
                },
                SchoolYear = new SchoolYear
                {
                    SchoolYearID = 1,
                    Start = new DateTime(2014, 8, 29),
                    End = new DateTime(2015, 5, 3)
                }
            };

            try
            {
                // Act
                session.CRN = "";
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void SessionCRN_Null_ArgumentNullException()
        {
            // Arrange
            var assert = false;
            var session = new Session
            {
                CRN = "1904",
                Capacity = 30,
                Course = new Course
                {
                    CourseID = 1,
                    Subject = "CIT",
                    Number = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    Online = false,
                    Hybrid = false
                },
                Instructor = new Instructor
                {
                    InstructorID = 1,
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    OfficeNumber = "IS201"
                },
                Semester = new Semester
                {
                    SemesterID = 1,
                    Name = "Spring"
                },
                SchoolYear = new SchoolYear
                {
                    SchoolYearID = 1,
                    Start = new DateTime(2014, 8, 29),
                    End = new DateTime(2015, 5, 3)
                }
            };

            try
            {
                // Act
                session.CRN = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void SessionCRN_BelowRange_ArgumentOutOfRangeException()
        {
            // Arrange
            var assert = false;
            var session = new Session
            {
                CRN = "1904",
                Capacity = 30,
                Course = new Course
                {
                    CourseID = 1,
                    Subject = "CIT",
                    Number = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    Online = false,
                    Hybrid = false
                },
                Instructor = new Instructor
                {
                    InstructorID = 1,
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    OfficeNumber = "IS201"
                },
                Semester = new Semester
                {
                    SemesterID = 1,
                    Name = "Spring"
                },
                SchoolYear = new SchoolYear
                {
                    SchoolYearID = 1,
                    Start = new DateTime(2014, 8, 29),
                    End = new DateTime(2015, 5, 3)
                }
            };

            try
            {
                // Act
                session.CRN = "190";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void SessionCRN_AboveRange_ArgumentOutOfRangeException()
        {
            // Arrange
            var assert = false;
            var session = new Session
            {
                CRN = "1904",
                Capacity = 30,
                Course = new Course
                {
                    CourseID = 1,
                    Subject = "CIT",
                    Number = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    Online = false,
                    Hybrid = false
                },
                Instructor = new Instructor
                {
                    InstructorID = 1,
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    OfficeNumber = "IS201"
                },
                Semester = new Semester
                {
                    SemesterID = 1,
                    Name = "Spring"
                },
                SchoolYear = new SchoolYear
                {
                    SchoolYearID = 1,
                    Start = new DateTime(2014, 8, 29),
                    End = new DateTime(2015, 5, 3)
                }
            };

            try
            {
                // Act
                session.CRN = "19041";
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        #endregion

        #region [ Capacity ]

        [TestMethod]
        public void SessionCapacity_BelowRange_ArgumentOutOfRangeException()
        {
            // Arrange
            var assert = false;
            var session = new Session
            {
                CRN = "1904",
                Capacity = 30,
                Course = new Course
                {
                    CourseID = 1,
                    Subject = "CIT",
                    Number = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    Online = false,
                    Hybrid = false
                },
                Instructor = new Instructor
                {
                    InstructorID = 1,
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    OfficeNumber = "IS201"
                },
                Semester = new Semester
                {
                    SemesterID = 1,
                    Name = "Spring"
                },
                SchoolYear = new SchoolYear
                {
                    SchoolYearID = 1,
                    Start = new DateTime(2014, 8, 29),
                    End = new DateTime(2015, 5, 3)
                }
            };

            try
            {
                // Act
                session.Capacity = 0;
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        [TestMethod]
        public void SessionCapacity_AboveRange_ArgumentOutOfRangeException()
        {
            // Arrange
            var assert = false;
            var session = new Session
            {
                CRN = "1904",
                Capacity = 30,
                Course = new Course
                {
                    CourseID = 1,
                    Subject = "CIT",
                    Number = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    Online = false,
                    Hybrid = false
                },
                Instructor = new Instructor
                {
                    InstructorID = 1,
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    OfficeNumber = "IS201"
                },
                Semester = new Semester
                {
                    SemesterID = 1,
                    Name = "Spring"
                },
                SchoolYear = new SchoolYear
                {
                    SchoolYearID = 1,
                    Start = new DateTime(2014, 8, 29),
                    End = new DateTime(2015, 5, 3)
                }
            };

            try
            {
                // Act
                session.Capacity = 51;
            }
            catch (ArgumentOutOfRangeException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
            }
        }

        #endregion

        #region [ CourseID ]

        [TestMethod]
        public void SessionCourseID_DefaultValue_EqualsExpected()
        {
            // Arrange
            var session = new Session();

            // Assert
            Assert.AreEqual(0, session.CourseID);
        }

        [TestMethod]
        public void SessionCourseID_ValidCourse_IDsAreEqual()
        {
            // Arrange
            var session = new Session
            {
                CRN = "1904",
                Capacity = 30,
                Course = new Course
                {
                    CourseID = 1,
                    Subject = "CIT",
                    Number = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    Online = false,
                    Hybrid = false
                },
                Instructor = new Instructor
                {
                    InstructorID = 1,
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    OfficeNumber = "IS201"
                },
                Semester = new Semester
                {
                    SemesterID = 1,
                    Name = "Spring"
                },
                SchoolYear = new SchoolYear
                {
                    SchoolYearID = 1,
                    Start = new DateTime(2014, 8, 29),
                    End = new DateTime(2015, 5, 3)
                }
            };

            // Assert
            Assert.AreEqual(session.Course.CourseID, session.CourseID);
        }

        #endregion

        #region [ InstructorID ]

        [TestMethod]
        public void SessionInstructorID_DefaultValue_EqualsExpected()
        {
            // Arrange
            var session = new Session();

            // Assert
            Assert.AreEqual(0, session.InstructorID);
        }

        [TestMethod]
        public void SessionInstructorID_ValidInstructor_IDsAreEqual()
        {
            // Arrange
            var session = new Session
            {
                CRN = "1904",
                Capacity = 30,
                Course = new Course
                {
                    CourseID = 1,
                    Subject = "CIT",
                    Number = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    Online = false,
                    Hybrid = false
                },
                Instructor = new Instructor
                {
                    InstructorID = 1,
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    OfficeNumber = "IS201"
                },
                Semester = new Semester
                {
                    SemesterID = 1,
                    Name = "Spring"
                },
                SchoolYear = new SchoolYear
                {
                    SchoolYearID = 1,
                    Start = new DateTime(2014, 8, 29),
                    End = new DateTime(2015, 5, 3)
                }
            };

            // Assert
            Assert.AreEqual(session.Instructor.InstructorID, session.InstructorID);
        }

        #endregion

        #region [ SemesterID ]

        [TestMethod]
        public void SessionSemesterID_DefaultValue_EqualsExpected()
        {
            // Arrange
            var session = new Session();

            // Assert
            Assert.AreEqual(0, session.SemesterID);
        }

        [TestMethod]
        public void SessionSemesterID_ValidSemester_IDsAreEqual()
        {
            // Arrange
            var session = new Session
            {
                CRN = "1904",
                Capacity = 30,
                Course = new Course
                {
                    CourseID = 1,
                    Subject = "CIT",
                    Number = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    Online = false,
                    Hybrid = false
                },
                Instructor = new Instructor
                {
                    InstructorID = 1,
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    OfficeNumber = "IS201"
                },
                Semester = new Semester
                {
                    SemesterID = 1,
                    Name = "Spring"
                },
                SchoolYear = new SchoolYear
                {
                    SchoolYearID = 1,
                    Start = new DateTime(2014, 8, 29),
                    End = new DateTime(2015, 5, 3)
                }
            };

            // Assert
            Assert.AreEqual(session.Semester.SemesterID, session.SemesterID);
        }

        #endregion

        #region [ SchoolYearID ]

        [TestMethod]
        public void SessionSchoolYearID_DefaultValue_EqualsExpected()
        {
            // Arrange
            var session = new Session();

            // Assert
            Assert.AreEqual(0, session.SchoolYearID);
        }

        [TestMethod]
        public void SessionSchoolYearID_ValidSchoolYear_IDsAreEqual()
        {
            // Arrange
            var session = new Session
            {
                CRN = "1904",
                Capacity = 30,
                Course = new Course
                {
                    CourseID = 1,
                    Subject = "CIT",
                    Number = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    Online = false,
                    Hybrid = false
                },
                Instructor = new Instructor
                {
                    InstructorID = 1,
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    OfficeNumber = "IS201"
                },
                Semester = new Semester
                {
                    SemesterID = 1,
                    Name = "Spring"
                },
                SchoolYear = new SchoolYear
                {
                    SchoolYearID = 1,
                    Start = new DateTime(2014, 8, 29),
                    End = new DateTime(2015, 5, 3)
                }
            };

            // Assert
            Assert.AreEqual(session.SchoolYear.SchoolYearID, session.SchoolYearID);
        }

        #endregion

        #region [ Course ]

        [TestMethod]
        public void SessionCourse_Null_ArgumentNullException()
        {
            // Arrange
            var assert = false;
            var session = new Session
            {
                CRN = "1904",
                Capacity = 30,
                Course = new Course
                {
                    CourseID = 1,
                    Subject = "CIT",
                    Number = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    Online = false,
                    Hybrid = false
                },
                Instructor = new Instructor
                {
                    InstructorID = 1,
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    OfficeNumber = "IS201"
                },
                Semester = new Semester
                {
                    SemesterID = 1,
                    Name = "Spring"
                },
                SchoolYear = new SchoolYear
                {
                    SchoolYearID = 1,
                    Start = new DateTime(2014, 8, 29),
                    End = new DateTime(2015, 5, 3)
                }
            };

            try
            {
                // Act
                session.Course = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
                Assert.IsNotNull(session.Course);
            }
        }

        #endregion

        #region [ Instructor ]

        [TestMethod]
        public void SessionInstructor_Null_ArgumentNullException()
        {
            // Arrange
            var assert = false;
            var session = new Session
            {
                CRN = "1904",
                Capacity = 30,
                Course = new Course
                {
                    CourseID = 1,
                    Subject = "CIT",
                    Number = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    Online = false,
                    Hybrid = false
                },
                Instructor = new Instructor
                {
                    InstructorID = 1,
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    OfficeNumber = "IS201"
                },
                Semester = new Semester
                {
                    SemesterID = 1,
                    Name = "Spring"
                },
                SchoolYear = new SchoolYear
                {
                    SchoolYearID = 1,
                    Start = new DateTime(2014, 8, 29),
                    End = new DateTime(2015, 5, 3)
                }
            };

            try
            {
                // Act
                session.Instructor = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
                Assert.IsNotNull(session.Instructor);
            }
        }

        #endregion

        #region [ Semester ]

        [TestMethod]
        public void SessionSemester_Null_ArgumentNullException()
        {
            // Arrange
            var assert = false;
            var session = new Session
            {
                CRN = "1904",
                Capacity = 30,
                Course = new Course
                {
                    CourseID = 1,
                    Subject = "CIT",
                    Number = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    Online = false,
                    Hybrid = false
                },
                Instructor = new Instructor
                {
                    InstructorID = 1,
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    OfficeNumber = "IS201"
                },
                Semester = new Semester
                {
                    SemesterID = 1,
                    Name = "Spring"
                },
                SchoolYear = new SchoolYear
                {
                    SchoolYearID = 1,
                    Start = new DateTime(2014, 8, 29),
                    End = new DateTime(2015, 5, 3)
                }
            };

            try
            {
                // Act
                session.Semester = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
                Assert.IsNotNull(session.Semester);
            }
        }

        #endregion

        #region [ SchoolYear ]

        [TestMethod]
        public void SessionSchoolYear_Null_ArgumentNullException()
        {
            // Arrange
            var assert = false;
            var session = new Session
            {
                CRN = "1904",
                Capacity = 30,
                Course = new Course
                {
                    CourseID = 1,
                    Subject = "CIT",
                    Number = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    Online = false,
                    Hybrid = false
                },
                Instructor = new Instructor
                {
                    InstructorID = 1,
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    OfficeNumber = "IS201"
                },
                Semester = new Semester
                {
                    SemesterID = 1,
                    Name = "Spring"
                },
                SchoolYear = new SchoolYear
                {
                    SchoolYearID = 1,
                    Start = new DateTime(2014, 8, 29),
                    End = new DateTime(2015, 5, 3)
                }
            };

            try
            {
                // Act
                session.SchoolYear = null;
            }
            catch (ArgumentNullException)
            {
                assert = true;
            }
            finally
            {
                // Assert
                Assert.IsTrue(assert);
                Assert.IsNotNull(session.SchoolYear);
            }
        }

        #endregion

        #region [ ToString() ]

        [TestMethod]
        public void SessionToString_ManualRepresentation_EqualsReturn()
        {
            // Arrange
            const string manualRep = "1904 - CIT190 - JavaScript Programming - Spring 2014-2015";
            var session = new Session
            {
                CRN = "1904",
                Capacity = 30,
                Course = new Course
                {
                    CourseID = 1,
                    Subject = "CIT",
                    Number = "190",
                    Title = "JavaScript Programming",
                    CreditHours = 2,
                    ContactHours = 2,
                    Online = false,
                    Hybrid = false
                },
                Instructor = new Instructor
                {
                    InstructorID = 1,
                    FirstName = "Ryan",
                    LastName = "Redburn",
                    PhoneNumber = "123-456-7890",
                    Email = "rredburn@email.com",
                    OfficeNumber = "IS201"
                },
                Semester = new Semester
                {
                    SemesterID = 1,
                    Name = "Spring"
                },
                SchoolYear = new SchoolYear
                {
                    SchoolYearID = 1,
                    Start = new DateTime(2014, 8, 29),
                    End = new DateTime(2015, 5, 3)
                }
            };

            // Assert
            Assert.AreEqual(manualRep, session.ToString());
        }

        #endregion
    }
}
